package goodenglish.application.impl;

import goodenglish.application.StudyPlanService;
import goodenglish.domain.model.lexicon.Lexicon;
import goodenglish.domain.model.lexicon.StudyInfo;
import goodenglish.domain.model.lexicon.StudyPlan;
import goodenglish.domain.model.lexicon.StudyPlanFactory;
import goodenglish.domain.model.studyplan.StudyPlanRepository;
import goodenglish.infrastructure.repository.db.StudyPlanRepositoryDb;
import goodenglish.interfaces.BeanFactory;

public class StudyPlanServiceImpl implements StudyPlanService {
	@Override
	public StudyPlan addStudyPlan(Lexicon lexicon) {
		StudyPlan studyPlan = studyPlanFactory.createStudyPlan(lexicon);

		studyPlanRepository.addStudyPlan(lexicon.getId(), studyPlan);
		lexicon.addStudyPlan(studyPlan);
		return studyPlan;

	}

	@Override
	public void addRightCount(StudyInfo studyInfo) {
		studyInfo.addRightCount();
		studyPlanRepository.updateNewWordRightCount(studyInfo);
	}

	@Override
	public void addWrongCount(StudyInfo studyInfo) {
		studyInfo.addWrongCount();
		studyPlanRepository.updateNewWordRightCount(studyInfo);
	}

	private StudyPlanFactory studyPlanFactory = BeanFactory.getSingleInstance(StudyPlanFactory.class);
	private StudyPlanRepository studyPlanRepository = BeanFactory.getSingleInstance(StudyPlanRepositoryDb.class);
}
